const Router = require('@koa/router');
const send = require('koa-send');

const router = new Router();

//--- Root Path -----------

router.get('/', async (ctx, next) => {
    // ctx.router available
    // ctx.body = ' body in root ';
    console.log(' get root. ');
    await send(ctx, '/index.html');
    next();
});

// //------- Action --------------
const { PickRouter } = require('./pick');
PickRouter(router);

//--------- Static Files ------------
router.all(/((\.js)|(\.jsx))|(\.vue)$/i, async (ctx, next) => {
    console.log(' *.js ', ctx.path, Date.now());
    ctx.set('Content-Type', 'application/x-javascript');
    await send(ctx, ctx.path);
    next();
});

router.all(/((\.html)|(\.htm))$/i, async (ctx, next) => {
    await send(ctx, ctx.path);
    next();
});

router.all(/\.css$/i, async (ctx, next) => {
    ctx.set('Content-Type', 'text/css')
    await send(ctx, ctx.path);
    next();
});

module.exports.router = router;